<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Oficial site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/

if (!defined ('EXPLAY')) exit;

past_path ( array (array ('', 'Черный список')));

print "\n<script>document.title='Черный список  - ".$SITE['site_name']."';</script>";

add_blackip ();

if (isset($_GET['delete'])) {
	$db->query("DELETE FROM ".DB_PEREFIX."_blacklist WHERE id = ".$_GET['delete']);
	site_message ('Ip удален');
}

if (isset($_GET['save'])) {
	if ($_POST['user_ip'] != '' ){
		$db->query("INSERT INTO ".DB_PEREFIX."_blacklist VALUES (0, '".$_POST['user_ip']."')");
		site_message ('Ip добавлен');
	}
	else site_error ('Не введен ip');
}

$get_list = $db->query ("SELECT * FROM ".DB_PEREFIX."_blacklist ORDER BY ip DESC");

if ($db->num_rows($get_list) > 0) {
	
	$list_tr = '';
	
	while (list($id, $ip) = $db->fetch_row($get_list)) {
		$list_tr .= "\r\n<tr><td class=\"ad_tr\" align=\"center\">$ip</td>".
			"<td class=\"ad_tr\" align=\"center\"><a href='javascript:delete_(\"admin.php?do=black_list&delete=true&id=$id\");'>удалить</a></td></tr>";
	}
	
	$list_table = "\n<table align=\"center\" class=\"body_table\" width=\"30%\" cellspacing=\"0\" cellpadding=\"3\">
	<tr>
		<td class=\"top_header_name\">IP</td>
		<td class=\"top_header_name\">Опции</td>
	</tr>$list_tr
</table><script>function delete_ (url_) { if (window.confirm('Вы действительно хотите удалить ip?') == true) document.location.href = url_; }</script>";
		
		past_table ('Запрещенные IP', $list_table);
}
else site_error ("Список пуст");

function add_blackip () {
	$form = "<form method=\"post\" action=\"admin.php?do=black_list&save\">
<table class=\"main_text\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
	<tr>
		<td width=\"25%\">Ip пользователя:</td>
		<td><input type=\"text\" style=\"width:50%\" name=\"user_ip\" /></td>
	</tr>
	<tr>
		<td colspan=\"2\"><input type=\"submit\" value=\"Добавить ip\" /></td>
	</tr>
</table>
</form>";
	
	past_table ('Добавить ip в черный список', $form);
}

come_back ('панели администратора', 'admin.php');

